<?php
/**
 * Created by PhpStorm.
 * User: thanatos
 * Date: 2017/12/5
 * Time: 下午3:47
 */

namespace common\models\search;


use common\models\Order;
use yii\data\ActiveDataProvider;

class OrderSearch extends Order{
    
    public function rules(){
        return [
            [['user_id'], 'required'],
            [['user_id'], 'integer'],
        ];
    }
    
    /**
     * @param $params
     * @return null|ActiveDataProvider
     */
    public function search($params){
        $this->attributes = $params;
        $query = static::find()->with('goods')->orderBy(['created_time' => SORT_DESC]);
        $dataProvider  = new ActiveDataProvider(['query' => $query]);
        
        if( !$this->validate() ){
            return null;
        }
        
        $query->andFilterWhere(['user_id' => $this->user_id]);
        
        return $dataProvider;
    }
}